const request=require('../../util/request.js')
import util from '../../util/util.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 0,//感觉没用 先放着
    fid: "1180",//fid
    pics: [ ],//采摘图片数组
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this 
    var params = {
      fid:options.fid,
    }
    this.setData({
      fid:options.fid
    })
    // return
    // that.setData({p_no:options})
    request.requestGet('fruit/get_bill_info', params, '',function (res) {
      that.setData({
        list:res.data,
        pics:res.data.pics
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  submit(event){
    var that = this
    let params = {
      id:that.data.id,
      fid:that.data.fid,
      pics:that.data.pics
    }
    request.requestAjax('fruit/save_bill_info',params,"提交中",function(res){
      if(res.status==200){
        wx.showToast({
          title: '操作成功',
          icon: 'success',
          duration: 1000,
          success: function() {
            setTimeout(function() {
              wx.navigateBack() 
            }, 1000);
          }
        });
        return false;
      }else{
        wx.showToast({
          title: res.msg,
          icon:"none"
        })
      }

  },function(res){
    wx.showToast({
      title: '请求失败',
      icon:"none"
    })
  });
  },
  delPic(e){
    console.log(e,"eeeeeeeeeee")
    var that = this;
    var index = e.currentTarget.dataset.index
    const pics = that.data.pics;
    pics.splice(index,1)
    that.setData({ pics });
  },

  uploadImage(){
    var that = this;
    util.uploadImageOne('upload/image', function (res){
      if(res.status==200){
        console.log(res,"ressssssssssssssss")
        let tmpurl = res.data.url
          const pics = that.data.pics;
          pics.push(tmpurl);
          that.setData({ pics });
          console.log(that.data.pics)
      }else{
        wx.showToast({
          title: '上传失败',
        })
      }
    });
  },


})